package com.ruoyi.web.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SuperComment;
import com.ruoyi.system.service.ISuperCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商品评论Controller
 * 
 * @author xjf
 * @date 2025-08-13
 */
@RestController
@RequestMapping("/comment/comments")
public class SuperCommentController extends BaseController
{
    @Autowired
    private ISuperCommentService superCommentService;

    /**
     * 查询商品评论列表
     */
    @PreAuthorize("@ss.hasPermi('comment:comments:list')")
    @GetMapping("/list")
    public TableDataInfo list(SuperComment superComment)
    {
        startPage();
        List<SuperComment> list = superCommentService.selectSuperCommentList(superComment);
        return getDataTable(list);
    }

    /**
     * 导出商品评论列表
     */
    @PreAuthorize("@ss.hasPermi('comment:comments:export')")
    @Log(title = "商品评论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SuperComment superComment)
    {
        List<SuperComment> list = superCommentService.selectSuperCommentList(superComment);
        ExcelUtil<SuperComment> util = new ExcelUtil<SuperComment>(SuperComment.class);
        util.exportExcel(response, list, "商品评论数据");
    }

    /**
     * 获取商品评论详细信息
     */
    @PreAuthorize("@ss.hasPermi('comment:comments:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(superCommentService.selectSuperCommentById(id));
    }

    /**
     * 新增商品评论
     */
    @PreAuthorize("@ss.hasPermi('comment:comments:add')")
    @Log(title = "商品评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SuperComment superComment)
    {
        Long commentId = superCommentService.insertSuperComment(superComment);
        return success(commentId);
    }

    /**
     * 修改商品评论
     */
    @PreAuthorize("@ss.hasPermi('comment:comments:edit')")
    @Log(title = "商品评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SuperComment superComment)
    {
        return toAjax(superCommentService.updateSuperComment(superComment));
    }

    /**
     * 删除商品评论
     */
    @PreAuthorize("@ss.hasPermi('comment:comments:remove')")
    @Log(title = "商品评论", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(superCommentService.deleteSuperCommentByIds(ids));
    }
}
